package com.network.util;

import com.lmax.disruptor.WorkHandler;
import com.network.dao.FileSaveDao;
import com.network.entity.FileSave;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 消息消费者
 */
@Component
public class Consumer<F> implements WorkHandler<FileSave> {

    Logger logger= LoggerFactory.getLogger(Consumer.class);

    @Autowired
    JdbcTemplate jdbcTemplate;
    @Resource
    FileSaveDao fileSaveDao;

    @Override
    public void onEvent(FileSave fileSave) throws Exception
    {
        logger.info("消费者******************************"+fileSave.getIp());
        jdbcTemplate=SpringBeanUtil.getBean(JdbcTemplate.class);

        String sql="INSERT INTO file_save_t(ip,equipment_name,file_name,file_path,file_size,file_suffix,file_type_name)"
                +" VALUES (?,?,?,?,?,?,?)";

       int num= jdbcTemplate.update(sql,fileSave.getIp(),fileSave.getEquipmentName(),fileSave.getFileName(),fileSave.getFilePath(),fileSave.getFileSize(),fileSave.getFileSuffix(),fileSave.getFileTypeName());

       if(num>0)
       {
           logger.info("*********************保存成功!");
       }

    }
}
